package com.winit.schedule.core.event;

/**
 * 所有事件的父类. 所有具体事件必须继承当前类
 */
public abstract class AbstractEvent<T extends Enum<T>> implements Event<T> {

    private final T type;
    private final long timestamp;

    /**
     * 不带触发时间的事件构造函数
     * 
     * @param type
     */
    public AbstractEvent(T type){
        this.type = type;
        // We're not generating a real timestamp here. It's too expensive.
        timestamp = -1L;
    }

    /**
     * 带触发事件的构造函数
     * 
     * @param type
     * @param timestamp
     */
    public AbstractEvent(T type, long timestamp){
        this.type = type;
        this.timestamp = timestamp;
    }

    @Override
    public long getTimestamp() {
        return timestamp;
    }

    @Override
    public T getType() {
        return type;
    }

    @Override
    public String toString() {
        return "EventType: " + getType();
    }
}
